#include<stdio.h>
#include<stdlib.h>
 
struct Lain
{
	int data;
	struct Lain *pre,*link;
};
 
struct Lain *Create();
void Shu(struct Lain *head);
void SShu(struct Lain *head);
struct Lain *Shuang(struct Lain *head);
 
int main()
{
	struct Lain *head;
	head=Create();   //创建符合题目的初始链表
	Shu(head);  //输出链表
	head=Shuang(head);
	SShu(head); 
	return 0;
}
 
struct Lain *Create()
{
	struct Lain *head=NULL,*p,*p1;
	p=(struct Lain *)malloc(sizeof(struct Lain));
	p->pre =NULL;
	p->link =NULL;
	scanf("%d",&p->data );
	while(p->data !=-1)
	{
		if(head==NULL)
		{
			head=p;
			p1=p;
		}
		else
		{
			p1->link =p;
			p1=p;
		}
		p=(struct Lain *)malloc(sizeof(struct Lain));
	    p->pre =NULL;
	    p->link =NULL;
	    scanf("%d",&p->data );
	}
	return head;
}
 
void Shu(struct Lain *head)
{
	struct Lain *p;
	p=head;
	while(p!=NULL )  
	{
		printf("%-3d",p->data );
		p=p->link ;
	}
	putchar('\n');
}
 
void SShu(struct Lain *head)
{
	struct Lain *p;
	p=head;
	while(p->link !=head )  
	{
		printf("%-3d",p->data );
		p=p->link ;
	}
	printf("%-3d",p->data );
	putchar('\n');    //这里主要是测试循环成功没有
	printf(":%d\n",p->link->data  );
	putchar('\n');
	printf(":%d\n",head->pre ->data  );
	putchar('\n');
}
 
 
struct Lain *Shuang(struct Lain *head)
{
	struct Lain *p,*l;
	p=head;
	l=head->link ;
	while(l!=NULL)
	{
		l->pre =p;
		p=p->link ;
		l=l->link ;
	}
	p->link =head;
	head->pre =p;
	return head;
}